<template>
  <div class="header">
    <!-- 左侧 -->
    <div class="l-content">
      <el-button size="small" @click="handleCollapse">
        <el-icon><Menu/></el-icon>
      </el-button>
      <el-breadcrumb separator="/" class="bread">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item v-if="current" :to="current.path">{{current.meta.title}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 右侧 -->
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img :src="getImageUrl()" alt="">
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLogout">退出登陆</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>
<script setup>
import { useSettingStore } from '@/store';
import { useRouter } from 'vue-router'
import { useUserInfoStore } from '@/store/userInfo.js'
import { computed } from 'vue'
const router = useRouter();
const getImageUrl = (user='default')=>{
  return new URL(`../assets/images/${user}.png`,import.meta.url).href
}
const settingStore = useSettingStore();
const current = computed(()=> settingStore.currentMenu)
const handleCollapse = ()=>{
  settingStore.isCollapse = !settingStore.isCollapse
}
const userInfoStore = useUserInfoStore();
const handleLogout = ()=>{
  userInfoStore.logout()
  router.push('/login')
}
</script>

<style lang="less" scoped>
.header{
  display: flex;
  justify-content: space-between;
  align-items: center;

  .l-content{
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .r-content{
    img{
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
  }
}
.el-tooltip__trigger:focus-visible {
    outline: unset;
}
:deep(.bread span){
  cursor: pointer !important;
}
</style>
